package WebServices
{
	import DataModel.SkillsAuditDocument;
	
	import flash.net.URLVariables;
	
	internal class UpdateDocumentResponder extends HttpResponder
	{
		public function UpdateDocumentResponder(auth:AuthenticationData, success:Function, failure:Function)
		{
			super(auth, success, failure);
		}

		public function callServer(service: SkillsAuditService):void
		{
			var xml:XML = 
			<EnumDataUpdateRequest>
				<SecurityContext>
					<UserName/>
					<UserPasswordMD5Hash/>
				</SecurityContext>
			</EnumDataUpdateRequest>
			
			xml.SecurityContext.UserName = m_authData.username;
			xml.SecurityContext.UserPasswordMD5Hash = m_authData.getDigest();
			
			xml.appendChild(SkillsAuditDocument.instance.toXML());
			
			service.setCallbacks(onSuccess, onFailure);
			var strXML:String = "xml="+xml.toXMLString();
			var myPattern:RegExp = /&/g;  
			strXML = strXML.replace(myPattern, "%26"); 
			service.request= new URLVariables(strXML);
			service.send();
					 
		}		
		
		override protected function onSuccess(xmlResponse:XML):void
		{
			if(xmlResponse.name().toString() != "EnumDataUpdateResponse")
			{
				onFailure(new Error("Invalid root element received from server. Expected 'EnumDataAccessResponse' received '" +xmlResponse.name().toString() + "'"));
				return;
			}
			super.onSuccess(xmlResponse);
		}
	}
}